package com.afish.syl.lib.api.core.acra;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.afish.syl.lib.api.config.StaticKeyUtils;
import com.afish.syl.lib.api.core.afishpublic.string.StrUtils;

import java.util.Timer;
import java.util.TimerTask;


/**
 *
 */
public class PackUtils {
    Context context;

    public PackUtils(Context context) {
        this.context = context;
        boolean b = false;
        if (b) {
        }
    }

    /**
     * @return
     */
    public String GetPackName() {
        String sPackName = getAppInfo(context);
        if (StrUtils.MD5_32(sPackName).equals(StaticKeyUtils.APP)) {
//        if (sPackName.equals(StaticKeyUtils.APP)) {
            return sPackName;
        } else {

            final Handler handler = new Handler() {

                public void handleMessage(Message msg) {

                    switch (msg.what) {

                        case 1:
//                            TextView v1= null;
//                            v1.setText("abc");
                            System.exit(0);
                            break;

                    }

                    super.handleMessage(msg);

                }

            };

            Timer timer = new Timer();

            TimerTask task = new TimerTask() {

                public void run() {

                    Message message = new Message();

                    message.what = 1;

                    handler.sendMessage(message);

                }

            };
            timer.schedule(task, 30000, 30000);
            return null;
        }
    }

    private String getAppInfo(Context context) {
        try {
            String pkName = context.getPackageName();
//            String versionName = context.getPackageManager().getPackageInfo(
//                    pkName, 0).versionName;
//            int versionCode = context.getPackageManager()
//                    .getPackageInfo(pkName, 0).versionCode;
//            return pkName + "   " + versionName + "  " + versionCode;
            return pkName;
        } catch (Exception e) {
        }
        return null;
    }
}
